package com.yyryyty.chapter6;

import com.yyryyty.chapter4.Dish;

import static com.yyryyty.chapter4.Dish.menu;
import static java.util.stream.Collectors.reducing;
import static java.util.stream.Collectors.summingInt;

/**
 * @Description :
 * @Author : YTY
 * @Date : 2021-01-18 08:00
 */
public class Reducing {

    public static void main(String[] args) {

        System.out.println(menu.stream()
                .collect(reducing(0, Dish::getCalories, Integer::sum)));

//        menu.stream().max(Comparator.comparingInt(Dish::getCalories))
//        menu.stream()
//                .mapToInt(Dish::getCalories)
//                .max().getAsInt()

//        System.out.println(menu.stream()
//                .collect(summingInt(Dish::getCalories)));

//        System.out.println(menu.stream()
//                .collect(summarizingInt(Dish::getCalories))
//                .getSum());
//
//        System.out.println(menu.stream()
//                .mapToInt(Dish::getCalories)
//                .sum());

//        System.out.println(menu.stream()
//                .mapToInt(Dish::getCalories)
//                .reduce(Integer::sum)
//                .orElse(1));

        System.out.println(menu.stream()
                .mapToInt(Dish::getCalories)
                .sum());

        System.out.println(menu.stream()
                .collect(summingInt(Dish::getCalories)));

//        menu.stream()
//                .mapToInt(Dish::getCalories).sum()

    }
}
